<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>作用域</title>
</head>
<body>
	<script>
		 var num=10;
		 function fn(){
		 	// var num; 
		 	num=11;
		 	console.log(num);
		 }
          
		 fn();
		console.log(num);
		 function aa(num1,num2){
		 	return num1*num2;
		 }
		 function bb(num1,num2){
		 	return num1+num2;
		 }
		 function cc(num1,num2){
		 	return num1-num2;
		 }
		 function math(num1,num2,fn){
		    return fn(num1,num2);
		 }
		 console.log(math(6,3,cc));
		 //映射返回偶数
		 var arr=[1,2,3,4,5,6,7,8,9,10]
		 var result=filter(arr,function(value){
		 	if( value%2==0){
		 		return value;
		 	}	
		 });
		 console.log(result);

		 function filter(arr1,num){    
		 	var newarr=[];
		   for(var i=0;i<arr1.length;i++){
	       	if(num(arr1[i])){
	       		newarr[newarr.length]=arr1[i];
	       	}		   	
		   }
		   return newarr;	
		 }
		 //映射数组每个值加2
		 var arr=[12,34,54,30,15]
		 var result=map(arr,function(value){
		 	return  value+2;
		 });
		 console.log(result);

		 function map(arr1,fn){
		 	var newarr=[];
		 	for(var i=0;i<arr1.length;i++){
		 		newarr[newarr.length]=fn(arr1[i])
		 	}
		 	return newarr;
		 }

	</script>
</body>
</html>